<?php
/* LIND - Lind Is Not a Dictionary
   =============================== */


class LindLayout {
  var $layout_pure;
  var $layout_parsed;
  var $layout_parts;

  var $title;
  var $content;
  var $navigation;

  function LindLayout($layout) {
    $this->layout_pure = @file_get_contents(LIND_LAYOUT_PATH.$layout);
    $this->layout_parts = $this->find_tags();
  }

  function find_tags() {
    $simples = array();
    if(preg_match_all('/<lind:(\w+)\s*(([a-z0-9]+="[a-z0-9]+"\s+)*)?\/>/', $this->layout_pure, $matches)) {
      for($i = 0; $i < sizeof($matches[0]); $i++) {
        $simples[] = array(
          'tag'  => $matches[0][$i],
          'name' => $matches[1][$i],
          'pars' => $matches[2][$i]
        );
      }
    }
    return($simples);
  }

  function join() {
    $this->layout_parsed = $this->layout_pure;
    foreach($this->layout_parts as $part) {
      $this->layout_parsed = str_replace($part['tag'], $this->$part['name'], $this->layout_parsed);
    }
  }
  
  function output() {
    return $this->layout_parsed;
  }
}

?>